package com.renting.modules.upyun.utils;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.Date;

public class UpYunUtils {


    public static String SEPARATOR = "/";

    public static String getVisitUrl(String serverPath, String originName) {
        String dateStr = DateUtil.format(new Date(), "yyyy-MM");
        String randomStr = RandomUtil.simpleUUID();
        String suffix = StrUtil.sub(originName, originName.lastIndexOf("."), originName.length());
        String visitUrl = serverPath + SEPARATOR + dateStr + SEPARATOR + randomStr + suffix;
        return visitUrl;
    }

    public static String getSuffix(String originName) {
        return StrUtil.sub(originName, originName.lastIndexOf("."), originName.length());
    }
}
